home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
music4c.sit
/
Music4C Folder
/
orchestras
/
HoweExample4.c
< prev
next >
Wrap
Text File
|
1990-08-07
|
2KB
|
101 lines
/*
* ⌐ Graeme Gerrard 1990
* Faculty of Music, University of Melbourne
* Parkville Victoria 3052 Australia.
*
* ARPANET: grae@murdu.ucs.unimelb.edu.au
* telephone: (613) 344 4127, Fax: (613) 344 5346
*/
#include "Music4C.h"
#include <math.h>
#include "ugens.h"
#include "orch.h"
#define MAXINS 5
static double *a;
static long sampno;
static long base;
extern Str255 theMess1;
void initl()
{
register long j;
a = (double *)NewPtr(MAXINS * 10 * sizeof(double));
if ( a == 0L )
fprintf(stderr, "Not enough memory in initl\n");
for ( j = 0; j < MAXINS * 10; j++ )
*(a+j) = 0.0;
}
void setup()
{
/*
* p4 = amp
* p5 = carrier freq in cps
* p6 = mod freq in cps
* p7 = first val of mod index
* p8 = final val of mod index
*
* F1 = sine
* F2 = amp env
* F3 = freq dev envelope
*/
if ( insno > MAXINS ) {
sprintf((char *)theMess1, "Instrument number %d is out of range", insno);
CtoPstr((char *)theMess1);
OSError(theMess1, NIL, NIL );
}
base = ((insno-1) * 10);
*(a+base) = period(p[3]);
/* Multiply by 30,000 so that we generate a reasonable amplitude for
* SD files, which are ▒32767 */
*(a+base+1) = p[4] * 30000.0;
*(a+base+2) = 0.0;
*(a+base+3) = cycle((p[8] - p[7]) * p[6]);
*(a+base+4) = 0.0;
*(a+base+5) = cycle(p[7] * p[6]);
*(a+base+6) = cycle(p[6]);
*(a+base+8) = cycle(p[5]);
}
void orch()
{
register double x;
register double y;
register base;
base = ((insno-1) * 10);
/* x = oscil1(*(a+base+1), *(a+base), 2, (a+base+2));
y = oscil1(*(a+base+3), *(a+base), 3, (a+base+4)) + *(a+base+5);
y = oscil(y, *(a+base+6), 1, (a+base+7)) + *(a+base+8);
x = oscil(x, y, 1, (a+base+9));
mono(x);
*/
/* in this case using the macros saves about 30% on the function call time */
Oscil1(x, *(a+base+1), *(a+base), 2, *(a+base+2));
Oscil1(y, *(a+base+3), *(a+base), 3, *(a+base+4));
y += *(a+base+5);
Oscil(y, y, *(a+base+6), 1, *(a+base+7));
y += *(a+base+8);
Oscil(x, x, y, 1, *(a+base+9));
Mono(x);
}
void ter()
{
/* just gets called at the end a note for clean up etc. */
}
void final()
{
/* called at the end of the synth run.
* close any files etc. you haven't already closed here.
*/
}